package com.myaihui.controller.admin;

import com.myaihui.domain.CarDossier;
import com.myaihui.domain.SysUser;
import com.myaihui.foundation.model.Pager;
import com.myaihui.foundation.model.StatusResponse;
import com.myaihui.foundation.msg.ResultMsg;
import com.myaihui.foundation.query.CarDossierQuery;
import com.myaihui.service.CarDossierService;
import com.myaihui.service.SysUserService;
import com.myaihui.util.LoginUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/car_dossier")
public class CarDossierController {
    @Autowired
    private CarDossierService carDossierService;

    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("/")
    public ModelAndView home(){
        ModelAndView modelAndView = new ModelAndView("carDossier/home");
        return modelAndView;
    }

    @RequestMapping("/page")
    @ResponseBody
    public Pager<CarDossier> page(CarDossierQuery query){
        SysUser sysUser = sysUserService.findByUsername(LoginUtil.loginUser().getUsername());
        query.setType(sysUser.getType());
        query.setPlatformId(sysUser.getPlatformId());
        if (query.getStatus() ==-1)
            query.setStatus(null);
        return carDossierService.findByConditions(query);
    }

    @RequestMapping("/{id}")
    public ModelAndView page(@PathVariable String id){
        ModelAndView modelAndView = new ModelAndView("carDossier/detail");
        modelAndView.addObject("carDossier", carDossierService.detail(id));
        return modelAndView;
    }

    @RequestMapping("/audit/{id}")
    @ResponseBody
    public ResultMsg audit(@PathVariable String id, Integer status, String remark){
        carDossierService.audit(id, status, remark);
        return ResultMsg.success(true);
    }
}
